package com.woniuxy.demo.epai.controller;


import com.woniuxy.demo.epai.common.Result;
import com.woniuxy.demo.epai.model.AuctionRecord;
import com.woniuxy.demo.epai.model.Members;
import com.woniuxy.demo.epai.model.Product;
import com.woniuxy.demo.epai.model.User;
import com.woniuxy.demo.epai.service.AliPayService;
import com.woniuxy.demo.epai.service.IAuctionRecordService;
import com.woniuxy.demo.epai.service.IMembersService;
import com.woniuxy.demo.epai.service.impl.AuctionRecordServiceImpl;
import com.woniuxy.demo.epai.service.impl.UserServiceImpl;
import com.woniuxy.demo.epai.vo.Alivo;
import com.woniuxy.demo.epai.vo.ArecordVo;
import com.woniuxy.demo.epai.vo.OrderVo;
import com.woniuxy.demo.epai.vo.RecordVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 出价记录表 前端控制器
 * </p>
 *
 * @author epai
 * @since 2021-04-12
 */
@RestController
@RequestMapping("/epai/auction-record")
@Slf4j
public class AuctionRecordController {
    @Autowired
    private IAuctionRecordService auctionRecordService;

    @Autowired
    private IMembersService iMembersService;

    @Autowired
    private AliPayService aliPayService;

    @GetMapping("/getrecord")
    public Result getRecord(int pid){
        log.info("查询商品{}",pid);
        List<ArecordVo> record = auctionRecordService.getRecord(pid);
        return Result.success(record);
    }

    @PostMapping("/addrecord")
    public Result addrecord(@RequestBody RecordVo recordVo){
        log.info("传入参数{}",recordVo);
        Members members = iMembersService.getMembers(recordVo.getUid());
        if(members!=null){
            if (members.getCredit()>=100 || recordVo.getMode().equals("会场模式")) {
                boolean b = aliPayService.dopaiSuccess(recordVo);
                if(b){
                    return Result.success();
                }
                return Result.fail("出价低于最高价或你已经是最高价");
            }
            return Result.fail("信用分不够,不能竞拍");
        }
        return Result.fail("用户不存在");
    }
}

